import java.util.Random;

public class EventPool {
	public static final int CANDIDATE_LIST_SIZE = 7;

	public static final int POOL_SIZE = 35;
	
	public static final int CLEAR_EDIT_TEXT              = 0;
	public static final int CLICK_LIST                   = 1;
	public static final int CLICK_LIST_LONG              = 2;
	public static final int CLICK_SCREEN_LONG            = 3;
	public static final int CLICK_TEXT_LONG              = 4;
	public static final int CLICK_TEXT_LONG_PRESS        = 5;
	public static final int CLICK_VIEW_LONG              = 6;
	public static final int CLICK_ACTION_BAR_HOME_BUTTON = 7;
	public static final int CLICK_ACTION_BAR_ITEM        = 8;
	public static final int CLICK_BUTTON                 = 9;
	public static final int CLICK_CHECKBOX               = 10;
	public static final int CLICK_EDIT_TEXT              = 11;
	public static final int CLICK_IMAGE                  = 12;
	public static final int CLICK_IMAGE_BUTTON           = 13;
	public static final int CLICK_MENU_ITEM              = 14;
	public static final int CLICK_RADIO_BUTTON           = 15;
	public static final int CLICK_SCREEN                 = 16;
	public static final int CLICK_TEXT                   = 17;
	public static final int CLICK_TOGGLE_BUTTON          = 18;
	public static final int CLICK_VIEW                   = 19;
	public static final int DRAG                         = 20;
	public static final int GO_BACK                      = 21;
	public static final int PRESS_MENU_ITEM              = 22;
	public static final int PRESS_SPINNER_ITEM           = 23;
	public static final int SCROLL_DOWN                  = 24;
	public static final int SCROLL_BOTTOM                = 25;
	public static final int SCROLL_TOP                   = 26;
	public static final int SCROLL_SIDE                  = 27;
	public static final int SCROLL_UP                    = 28;
	public static final int SEND_KEY                     = 29;
	public static final int SET_ACTIVITY_ORIENTATION     = 30;
	public static final int TYPE_TEXT1                   = 31;
	public static final int TYPE_TEXT2                   = 32;
	public static final int TYPE_NUMBER1                 = 33;
	public static final int TYPE_NUMBER2                 = 34;

	private String[] stringEncoding;

	private boolean[] valid;

	public EventPool() {
		this.valid = new boolean[EventPool.POOL_SIZE];

		this.valid[EventPool.CLEAR_EDIT_TEXT]              = true;
		this.valid[EventPool.CLICK_LIST]                   = false;
		this.valid[EventPool.CLICK_LIST_LONG]              = false;
		this.valid[EventPool.CLICK_SCREEN_LONG]            = true;
		this.valid[EventPool.CLICK_TEXT_LONG]              = false;
		this.valid[EventPool.CLICK_TEXT_LONG_PRESS]        = false;
		this.valid[EventPool.CLICK_VIEW_LONG]              = false;
		this.valid[EventPool.CLICK_ACTION_BAR_HOME_BUTTON] = false;
		this.valid[EventPool.CLICK_ACTION_BAR_ITEM]        = false;
		this.valid[EventPool.CLICK_BUTTON]                 = true;
		this.valid[EventPool.CLICK_CHECKBOX]               = false;
		this.valid[EventPool.CLICK_EDIT_TEXT]              = true;
		this.valid[EventPool.CLICK_IMAGE]                  = false;
		this.valid[EventPool.CLICK_IMAGE_BUTTON]           = false;
		this.valid[EventPool.CLICK_MENU_ITEM]              = false;
		this.valid[EventPool.CLICK_RADIO_BUTTON]           = false;
		this.valid[EventPool.CLICK_SCREEN]                 = true;
		this.valid[EventPool.CLICK_TEXT]                   = false;
		this.valid[EventPool.CLICK_TOGGLE_BUTTON]          = false;
		this.valid[EventPool.CLICK_VIEW]                   = false;
		this.valid[EventPool.DRAG]                         = true;
		this.valid[EventPool.GO_BACK]                      = false;
		this.valid[EventPool.PRESS_MENU_ITEM]              = false;
		this.valid[EventPool.PRESS_SPINNER_ITEM]           = false;
		this.valid[EventPool.SCROLL_DOWN]                  = true;
		this.valid[EventPool.SCROLL_BOTTOM]                = true;
		this.valid[EventPool.SCROLL_TOP]                   = true;
		this.valid[EventPool.SCROLL_SIDE]                  = true;
		this.valid[EventPool.SCROLL_UP]                    = true;
		this.valid[EventPool.SEND_KEY]                     = false;
		this.valid[EventPool.SET_ACTIVITY_ORIENTATION]     = true;
		this.valid[EventPool.TYPE_TEXT1]                   = true;
		this.valid[EventPool.TYPE_TEXT2]                   = true;
		this.valid[EventPool.TYPE_NUMBER1]                 = true;
		this.valid[EventPool.TYPE_NUMBER2]                 = true;

		this.stringEncoding = new String[EventPool.POOL_SIZE];

		this.stringEncoding[EventPool.CLEAR_EDIT_TEXT]              = "Clear Edit Text";
		this.stringEncoding[EventPool.CLICK_LIST]                   = "Click List";
		this.stringEncoding[EventPool.CLICK_LIST_LONG]              = "Click List Long";
		this.stringEncoding[EventPool.CLICK_SCREEN_LONG]            = "Click Screen Long";
		this.stringEncoding[EventPool.CLICK_TEXT_LONG]              = "Click Text Long";
		this.stringEncoding[EventPool.CLICK_TEXT_LONG_PRESS]        = "Click Text Long Press";
		this.stringEncoding[EventPool.CLICK_VIEW_LONG]              = "Click View Long";
		this.stringEncoding[EventPool.CLICK_ACTION_BAR_HOME_BUTTON] = "Click Action Bar Home Button";
		this.stringEncoding[EventPool.CLICK_ACTION_BAR_ITEM]        = "Click Action Bar Item";
		this.stringEncoding[EventPool.CLICK_BUTTON]                 = "Click Button";
		this.stringEncoding[EventPool.CLICK_CHECKBOX]               = "Click Checkbox";
		this.stringEncoding[EventPool.CLICK_EDIT_TEXT]              = "Click Edit Text";
		this.stringEncoding[EventPool.CLICK_IMAGE]                  = "Click Image";
		this.stringEncoding[EventPool.CLICK_IMAGE_BUTTON]           = "Click Image Button";
		this.stringEncoding[EventPool.CLICK_MENU_ITEM]              = "Click Menu Item";
		this.stringEncoding[EventPool.CLICK_RADIO_BUTTON]           = "Click Radio Button";
		this.stringEncoding[EventPool.CLICK_SCREEN]                 = "Click Screen";
		this.stringEncoding[EventPool.CLICK_TEXT]                   = "Click Text";
		this.stringEncoding[EventPool.CLICK_TOGGLE_BUTTON]          = "Click Toggle Button";
		this.stringEncoding[EventPool.CLICK_VIEW]                   = "Click View";
		this.stringEncoding[EventPool.DRAG]                         = "Click Drag";
		this.stringEncoding[EventPool.GO_BACK]                      = "Go Back";
		this.stringEncoding[EventPool.PRESS_MENU_ITEM]              = "Press Menu Item";
		this.stringEncoding[EventPool.PRESS_SPINNER_ITEM]           = "Press Spinner Item";
		this.stringEncoding[EventPool.SCROLL_DOWN]                  = "Scroll Down";
		this.stringEncoding[EventPool.SCROLL_BOTTOM]                = "Scroll Bottom";
		this.stringEncoding[EventPool.SCROLL_TOP]                   = "Scroll Top";
		this.stringEncoding[EventPool.SCROLL_SIDE]                  = "Scroll Side";
		this.stringEncoding[EventPool.SCROLL_UP]                    = "Scroll Up";
		this.stringEncoding[EventPool.SEND_KEY]                     = "Send Key";
		this.stringEncoding[EventPool.SET_ACTIVITY_ORIENTATION]     = "Set Activity Orientation";
		this.stringEncoding[EventPool.TYPE_TEXT1]                   = "Type Text 1";
		this.stringEncoding[EventPool.TYPE_TEXT2]                   = "Type Text 2";
		this.stringEncoding[EventPool.TYPE_NUMBER1]                 = "Type Number 1";
		this.stringEncoding[EventPool.TYPE_NUMBER2]                 = "Type Number 2";
	}
	
	public void setValid(int code, boolean val) {
		if (code >= 0 && code < EventPool.POOL_SIZE) {
			this.valid[code] = val;
		}
	}

	public Candidate createCandidate() {
		Random generator = new Random();
		Candidate c = new Candidate();

		for (int j = 0; j < Candidate.EVENT_LIST_SIZE; ++j) {
			int eventCode;

			do {
				eventCode = generator.nextInt(EventPool.POOL_SIZE);
			} while (!this.valid[eventCode]);

			c.addEvent(new Event(eventCode, this.stringEncoding[eventCode]));
		}

		return c;
	}
}
